#include <unistd.h>
#include <stdio.h>
#include <dirent.h>
#include <string.h>
#include <sys/stat.h>

void showdir(char * dir,int depth)
{
	DIR * dp;
	struct dirent *pdirent;
	struct stat statbuf;
	if ((dp=opendir(dir))==NULL)
	{
		fprintf(stderr,"can't open directory:%s\n",dir);
		return;
	}
	chdir(dir);
	while ((pdirent=readdir(dp))!=NULL)
	{
		stat(pdirent -> d_name,&statbuf);
		if (S_ISDIR(statbuf.st_mode))
		{
			if (strcmp(".",pdirent -> d_name)==0||strcmp("..",pdirent -> d_name)==0)
				continue;
			printf("Directory: %s (Depth: %d)\n",pdirent -> d_name,depth);
			if(depth==0)
				return;
			showdir(pdirent -> d_name,depth-1);
		}
		else
		{
			if(fnmatch("*.cls",pdirent ->d_name,,FNM_FILE_NAME)
				||fnmatch("*.cls",pdirent ->d_name,,FNM_FILE_NAME)
				||fnmatch("*.c",pdirent ->d_name,,FNM_FILE_NAME)
				||fnmatch("*.cpp",pdirent ->d_name,,FNM_FILE_NAME)
				||fnmatch("*.c",pdirent ->d_name,,FNM_FILE_NAME)
				||fnmatch("*.cls",pdirent ->d_name,,FNM_FILE_NAME)
				||fnmatch ("*.cls",pdirent ->d_name,,FNM_FILE_NAME)
				||fnmatch("*.cls",pdirent ->d_name,,FNM_FILE_NAME)
				||fnmatch("*.cls",pdirent ->d_name,,FNM_FILE_NAME)
			)
			{
				printf("dos2unix %s\n",pdirent ->d_name);		
			}		
		}
	}
	chdir("..");
	closedir(dp);
}

int main(int ac,char *av[]) 
{
	if(ac==1)
		showdir("/home/walter",3);
	else
	{
		while(--ac)
		{
			printf("%s:\n",*++av);
			showdir(*av,3);
		}
	}
	return 0;
}

